#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#include <string.h>
#include <stdio.h>
#include "ssd1306.h"
#include "oled.h"

const uint32_t W = 16, H = 16;

#if 1
uint8_t sig_fonts[32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共1个字符
[总字符库]："："*/

/*-- ID:0,字符:"：",ASCII编码:A3BA,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0F,0x00,
0x0F,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x0F,0x00,0x0F,0x00,0x06,0x00,0x00,0x00
};

/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共1个字符
[总字符库]："℃"*/
uint8_t sig1_fonts[32] = {
/*-- ID:0,字符:"℃",ASCII编码:A1E6,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
0x00,0x06,0x09,0x09,0xE6,0xF0,0x18,0x08,0x08,0x08,0x18,0x30,0x78,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x30,0x20,0x20,0x20,0x10,0x08,0x00,0x00,0x00
};

uint8_t button_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共2个字符
[总字符库]："开关"*/

/*-- ID:0,字符:"开",ASCII编码:BFAA,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x08,0x7F,0xFC,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x24,0xFF,0xFE,
0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x20,0x10,0x20,0x20,0x20,0x40,0x20,},

/*-- ID:1,字符:"关",ASCII编码:B9D8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x10,0x10,0x08,0x18,0x04,0x20,0x04,0x48,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x04,
0xFF,0xFE,0x01,0x00,0x02,0x80,0x02,0x80,0x04,0x40,0x08,0x30,0x30,0x0E,0xC0,0x04},
};

 //宠物智能管理系统
    uint8_t head_fonts[][32] = {
        /*-- ID:0,字符:"宠",ASCII编码:B3E8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       {0x02,0x00,0x01,0x00,0x7F,0xFE,0x42,0x02,0x82,0x84,0x02,0x50,0x3F,0xF8,0x02,0x80,
0x02,0x90,0x04,0xB0,0x04,0xC0,0x08,0x80,0x09,0x82,0x12,0x82,0x20,0x7E,0x40,0x00,
},

        /*-- ID:1,字符:"物",ASCII编码:CEEF,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       {0x11,0x00,0x11,0x00,0x51,0x00,0x51,0x04,0x7B,0xFE,0x54,0xA4,0x90,0xA4,0x1C,0xA4,
0x31,0x24,0xD1,0x44,0x12,0x44,0x12,0x44,0x14,0x84,0x10,0x84,0x11,0x28,0x10,0x10,},

        /*-- ID:2,字符:"智",ASCII编码:D6C7,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       {0x20,0x00,0x22,0x04,0x3F,0x7E,0x48,0x44,0x08,0x44,0xFF,0xC4,0x10,0x44,0x14,0x7C,
0x22,0x44,0x42,0x10,0x9F,0xF8,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,},

        /*-- ID:3,字符:"能",ASCII编码:C4DC,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       { 0x10,0x80,0x10,0x88,0x24,0x98,0x44,0xA0,0xFE,0xC0,0x02,0x84,0x7C,0x84,0x44,0x7C,
0x7C,0x00,0x44,0x88,0x44,0x98,0x7C,0xA0,0x44,0xC0,0x44,0x82,0x54,0x82,0x48,0x7E,},

        /*-- ID:4,字符:"管",ASCII编码:B9DC,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       {0x10,0x40,0x1F,0x7C,0x28,0x90,0x45,0x08,0x01,0x00,0x7F,0xFE,0x40,0x02,0x9F,0xF4,
0x10,0x10,0x1F,0xF0,0x10,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x00,},

        /*-- ID:5,字符:"理",ASCII编码:C0ED,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       { 0x00,0x08,0x13,0xFC,0xFA,0x48,0x22,0x48,0x23,0xF8,0x22,0x48,0xFA,0x48,0x23,0xF8,
0x20,0x40,0x20,0x50,0x23,0xF8,0x3C,0x40,0xE0,0x40,0x40,0x44,0x0F,0xFE,0x00,0x00,},

        /*-- ID:6,字符:"系",ASCII编码:CFB5,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       { 0x00,0x38,0x7F,0xC0,0x04,0x00,0x04,0x10,0x08,0x20,0x3F,0xC0,0x01,0x00,0x02,0x20,
0x04,0x10,0x3F,0xF8,0x01,0x08,0x09,0x20,0x09,0x10,0x11,0x08,0x25,0x08,0x02,0x00,},

        /*-- ID:7,字符:"统",ASCII编码:CDB3,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
       {0x10,0x80,0x10,0x40,0x20,0x48,0x27,0xFC,0x48,0x80,0xF9,0x10,0x12,0x08,0x27,0xFC,
0x41,0x24,0xF9,0x20,0x41,0x20,0x01,0x20,0x1A,0x22,0xE2,0x22,0x44,0x1E,0x08,0x00},
    };

//云平台控制
uint8_t cloud_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共5个字符
[总字符库]："云平台控制"*/

      /*-- ID:0,字符:"云",ASCII编码:D4C6,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x00,0x00,0x20,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00,0x04,0xFF,0xFE,0x02,0x00,
0x02,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x20,0x10,0x10,0x3F,0xF8,0x00,0x08,},

/*-- ID:1,字符:"平",ASCII编码:C6BD,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x08,0x7F,0xFC,0x01,0x00,0x11,0x10,0x11,0x10,0x09,0x20,0x09,0x20,0x01,0x04,
0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,},

/*-- ID:2,字符:"台",ASCII编码:CCA8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x02,0x00,0x02,0x00,0x04,0x00,0x08,0x20,0x10,0x10,0x20,0x08,0x7F,0xFC,0x00,0x04,
0x00,0x10,0x1F,0xF8,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,},

/*-- ID:3,字符:"控",ASCII编码:BFD8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x10,0x40,0x10,0x20,0x13,0xFE,0x12,0x02,0xFC,0x54,0x10,0x88,0x15,0x04,0x18,0x00,
0x30,0x08,0xD3,0xFC,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x24,0x57,0xFE,0x20,0x00,},

/*-- ID:4,字符:"制",ASCII编码:D6C6,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x04,0x04,0x24,0x04,0x25,0x04,0x3F,0xA4,0x24,0x24,0x44,0xA4,0xFF,0xE4,0x04,0x24,
0x3F,0xA4,0x24,0xA4,0x24,0xA4,0x24,0x84,0x26,0x84,0x25,0x04,0x04,0x14,0x04,0x08},
};


//温度
uint8_t temp_fonts[][32] = {
/*-- ID:0,字符:"温",ASCII编码:CEC2,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x08,0x43,0xFC,0x32,0x08,0x12,0x08,0x83,0xF8,0x62,0x08,0x22,0x08,0x0B,0xF8,
0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x20,0x00,},

/*-- ID:1,字符:"度",ASCII编码:B6C8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x01,0x00,0x00,0x84,0x3F,0xFE,0x22,0x20,0x22,0x28,0x3F,0xFC,0x22,0x20,0x23,0xE0,
0x20,0x00,0x2F,0xF0,0x22,0x20,0x21,0x40,0x20,0x80,0x43,0x60,0x8C,0x1E,0x30,0x04},
};

//湿度
uint8_t humi_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共2个字符
[总字符库]："湿度"*/

/*-- ID:0,字符:"湿",ASCII编码:CAAA,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x08,0x47,0xFC,0x34,0x08,0x14,0x08,0x87,0xF8,0x64,0x08,0x24,0x08,0x0F,0xF8,
0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x24,0x3F,0xFE,0x20,0x00,},

/*-- ID:1,字符:"度",ASCII编码:B6C8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x01,0x00,0x00,0x84,0x3F,0xFE,0x22,0x20,0x22,0x28,0x3F,0xFC,0x22,0x20,0x23,0xE0,
0x20,0x00,0x2F,0xF0,0x22,0x20,0x21,0x40,0x20,0x80,0x43,0x60,0x8C,0x1E,0x30,0x04},

};

//光照
uint8_t light_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共2个字符
[总字符库]："光照"*/

/*-- ID:0,字符:"光",ASCII编码:B9E2,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x01,0x00,0x21,0x08,0x11,0x0C,0x09,0x10,0x09,0x20,0x01,0x04,0xFF,0xFE,0x04,0x40,
0x04,0x40,0x04,0x40,0x04,0x40,0x08,0x40,0x08,0x42,0x10,0x42,0x20,0x3E,0x40,0x00,},

/*-- ID:1,字符:"照",ASCII编码:D5D5,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x04,0x7D,0xFE,0x44,0x44,0x44,0x44,0x44,0x84,0x44,0x94,0x7D,0x08,0x44,0xFC,
0x44,0x84,0x44,0x84,0x44,0x84,0x7C,0xFC,0x00,0x00,0x24,0x88,0x62,0x46,0x82,0x42},
};

//风扇
uint8_t fan_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共2个字符
[总字符库]："风扇"*/

/*-- ID:0,字符:"风",ASCII编码:B7E7,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x10,0x3F,0xF8,0x20,0x10,0x28,0x50,0x24,0x50,0x22,0x90,0x22,0x90,0x21,0x10,
0x21,0x10,0x22,0x90,0x22,0x90,0x24,0x50,0x28,0x50,0x30,0x12,0x40,0x0A,0x80,0x06,},

/*-- ID:1,字符:"扇",ASCII编码:C9C8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x02,0x00,0x01,0x08,0x3F,0xFC,0x20,0x08,0x20,0x08,0x3F,0xF8,0x20,0x00,0x20,0x04,
0x3F,0x7E,0x21,0x04,0x29,0x24,0x25,0x14,0x29,0x24,0x51,0x44,0x85,0x14,0x02,0x08},
};


//加热片
uint8_t ptc_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共3个字符
[总字符库]："加热片"*/

/*-- ID:0,字符:"加",ASCII编码:BCD3,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x10,0x00,0x10,0x00,0x10,0x04,0x12,0x7E,0xFF,0x44,0x12,0x44,0x12,0x44,0x12,0x44,
0x12,0x44,0x22,0x44,0x22,0x44,0x22,0x44,0x22,0x44,0x4A,0x7C,0x84,0x44,0x00,0x00,},

/*-- ID:1,字符:"热",ASCII编码:C8C8,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x08,0x40,0x08,0x40,0x08,0x48,0x7F,0xFC,0x08,0x48,0x0A,0x48,0x1C,0xC8,0x68,0x48,
0x08,0xA8,0x08,0x8A,0x29,0x0A,0x12,0x04,0x00,0x00,0x48,0x88,0x44,0x46,0x84,0x42,},

/*-- ID:2,字符:"片",ASCII编码:C6AC,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x84,0x3F,0xFE,0x20,0x00,0x20,0x00,
0x3F,0xC0,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x40,0x40,0x80,0x40},
};

//加湿器
uint8_t hdr_fonts[][32] = {
/* [字库]：[HZK1616宋体] [数据排列]:从左到右从上到下 [取模方式]:纵向8点下高位 [正负反色]:否 [去掉重复后]共3个字符
[总字符库]："加湿器"*/

/*-- ID:0,字符:"加",ASCII编码:BCD3,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
/*-- ID:0,字符:"加",ASCII编码:BCD3,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x10,0x00,0x10,0x00,0x10,0x04,0x12,0x7E,0xFF,0x44,0x12,0x44,0x12,0x44,0x12,0x44,
0x12,0x44,0x22,0x44,0x22,0x44,0x22,0x44,0x22,0x44,0x4A,0x7C,0x84,0x44,0x00,0x00,},

/*-- ID:1,字符:"湿",ASCII编码:CAAA,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x00,0x08,0x47,0xFC,0x34,0x08,0x14,0x08,0x87,0xF8,0x64,0x08,0x24,0x08,0x0F,0xF8,
0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x24,0x3F,0xFE,0x20,0x00,},

/*-- ID:2,字符:"器",ASCII编码:C6F7,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
{0x3E,0xF8,0x22,0x88,0x22,0x88,0x22,0x88,0x3E,0xF8,0x01,0x20,0x01,0x14,0xFF,0xFE,
0x02,0x80,0x0C,0x60,0x30,0x18,0xFE,0xFE,0x22,0x88,0x22,0x88,0x22,0x88,0x3E,0xF8},
};

const unsigned char gImage_sss[288] = { /* 0X00,0X01,0X2E,0X00,0X30,0X00, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFE,0X00,0X00,0X00,0X00,0X10,0X0F,
0XC0,0X00,0X00,0X00,0XC7,0X87,0XB0,0X00,0X00,0X00,0X00,0X03,0X8C,0X00,0X20,0X02,
0X00,0X21,0X87,0X80,0X44,0X0C,0X00,0X20,0X82,0X18,0X48,0X08,0X00,0X00,0XC1,0X04,
0X00,0X10,0X00,0XC0,0X80,0X84,0X00,0X20,0X07,0X00,0XC0,0X08,0X00,0X20,0X78,0X00,
0XC0,0X70,0X00,0X40,0X00,0X00,0XC0,0X40,0X00,0X40,0X00,0X00,0X40,0X20,0X00,0X80,
0X00,0X00,0X40,0X20,0X00,0X80,0X00,0X00,0X40,0X20,0X00,0XB0,0X00,0X00,0X60,0X20,
0X01,0X48,0X00,0X00,0X40,0X00,0X02,0X80,0X00,0X00,0X40,0X10,0X02,0X10,0X00,0X00,
0X00,0X10,0X05,0X10,0X00,0X00,0X40,0X10,0X04,0X10,0X00,0X00,0X00,0X10,0X0A,0X18,
0X00,0X00,0X00,0X10,0X0A,0X10,0X00,0X00,0X00,0X00,0X12,0X10,0X00,0X00,0X00,0X20,
0X12,0X00,0X00,0X00,0X00,0X20,0X22,0X00,0X01,0X00,0X00,0X00,0X22,0X00,0X01,0X80,
0X00,0X20,0X20,0X10,0X01,0X80,0X0C,0X20,0X40,0X10,0X00,0X00,0X00,0X00,0X40,0X08,
0X00,0X00,0X00,0X20,0X40,0X06,0X00,0X00,0X00,0X40,0X40,0X01,0XC0,0X1E,0X01,0X80,
0X40,0X00,0X18,0X00,0X3C,0X00,0X40,0X00,0X00,0X00,0X0A,0X50,0X40,0X00,0X00,0X00,
0X10,0X50,0X40,0X00,0X00,0X00,0XC1,0X80,0X40,0X0C,0X00,0X00,0X00,0XA0,0X40,0X00,
0X00,0X00,0X00,0X20,0X40,0X32,0X00,0X00,0X00,0X00,0X20,0X10,0X00,0X00,0X00,0X40,
0X20,0X09,0X00,0X00,0X00,0X40,0X10,0X09,0X00,0X00,0X01,0X80,0X08,0X00,0X00,0X00,
0X02,0X00,0X04,0X00,0X00,0X00,0X04,0X00,0X02,0X03,0X00,0X00,0X18,0X00,0X00,0X80,
0X02,0X48,0XC0,0X00,0X00,0X70,0X10,0X00,0X00,0X00,0X00,0X07,0X80,0X00,0X00,0X00,
};

void ssd1306_DrawBitmap(const uint8_t* bitmap, uint32_t size)
{
    uint8_t rows = size * 8 / SSD1306_WIDTH;
    if (rows > SSD1306_HEIGHT) {
        rows = SSD1306_HEIGHT;
    }
    for (uint8_t y = 0; y < rows; y++) {
        for (uint8_t x = 0; x < SSD1306_WIDTH; x++) {
            uint8_t byte = bitmap[(y * SSD1306_WIDTH / 8) + (x / 8)];
            uint8_t bit = byte & (0x80 >> (x % 8));
            ssd1306_DrawPixel(x, y, bit ? White : Black);
        }
    }
}

void ssd1306_DrawRegion(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t* data, uint32_t size, uint32_t stride)
{
    if (x + w > SSD1306_WIDTH || y + h > SSD1306_HEIGHT || w * h == 0) {
        //printf("%dx%d @ %d,%d out of range or invalid!\r\n", w, h, x, y);
        return;
    }

    w = (w <= SSD1306_WIDTH ? w : SSD1306_WIDTH);
    h = (h <= SSD1306_HEIGHT ? h : SSD1306_HEIGHT);
    stride = (stride == 0 ? w : stride);

    uint8_t rows = size * 8 / stride;
    for (uint8_t i = 0; i < rows; i++) {
        uint32_t base = i * stride / 8;
        for (uint8_t j = 0; j < w; j++) {
            uint32_t idx = base + (j / 8);
            uint8_t byte = idx < size ? data[idx] : 0;
            uint8_t bit  = byte & (0x80 >> (j % 8));
            ssd1306_DrawPixel(x + j, y + i, bit ? White : Black);
        }
    }
}

//https://icons8.com/icons/set/hamster
void ssd1306_bitmap_test(void)
{
    //https://www.23bei.com/tool-223.html
    uint8_t fonts[][32] = {
    /*-- ID:0,字符:"你",ASCII编码:C4E3,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
    {0x11,0x00,0x11,0x00,0x11,0x00,0x23,0xFC,0x22,0x04,0x64,0x08,0xA8,0x40,0x20,0x40,
    0x21,0x50,0x21,0x48,0x22,0x4C,0x24,0x44,0x20,0x40,0x20,0x40,0x21,0x40,0x20,0x80,},

    /*-- ID:1,字符:"好",ASCII编码:BAC3,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
    {0x10,0x00,0x11,0xFC,0x10,0x04,0x10,0x08,0xFC,0x10,0x24,0x20,0x24,0x24,0x27,0xFE,
    0x24,0x20,0x44,0x20,0x28,0x20,0x10,0x20,0x28,0x20,0x44,0x20,0x84,0xA0,0x00,0x40,},

    /*-- ID:2,字符:"仓",ASCII编码:B2D6,对应字:宽x高=16x16,画布:宽W=16 高H=16,共32字节*/
    {0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x80,0x04,0x40,0x08,0x20,0x30,0x1E,0xCF,0xE4,
    0x08,0x20,0x08,0x20,0x08,0xA0,0x08,0x40,0x08,0x08,0x08,0x08,0x07,0xF8,0x00,0x00},
    
    };

    ssd1306_Fill(Black);
    for (size_t i = 0; i < sizeof(fonts)/sizeof(fonts[0]); i++) {
        ssd1306_DrawRegion(i * W + 32, 0, W, H, fonts[i], sizeof(fonts[0]), W);
    }

    ssd1306_DrawRegion(3 * W + 32, 0, W, H, fonts[2], sizeof(fonts[0]), W);

    ssd1306_SetCursor(40, 0);
    //   128    40  48  40
    ssd1306_DrawRegion(40,16,48,48,gImage_sss,288,48);

    ssd1306_UpdateScreen();
}
#endif

void ssd1306_bitmap()
{
    ssd1306_Init();
    //ssd1306_TestCircle();
    // ssd1306_Fill(Black);
    ssd1306_bitmap_test();
    // rt_thread_mdelay(3000);
}

//主界面1
void ssd1306_set_main_1(uint32_t temp, uint32_t humi, uint32_t light)
{
       char buff[8];
       //绘制标题:  "宠物智能家居管理系统"
       ssd1306_Fill(Black);
       for (size_t i = 0; i < sizeof(head_fonts)/sizeof(head_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 0, W, H, head_fonts[i], sizeof(head_fonts[0]), W);
       }
       
       //温度
       for (size_t i = 0; i < sizeof(temp_fonts)/sizeof(temp_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 16, W, H, temp_fonts[i], sizeof(temp_fonts[0]), W);
       }
       //:
       ssd1306_DrawRegion(2 * W, 16, W, H, sig_fonts, sizeof(sig_fonts), W);
       //取数字
       ssd1306_SetCursor(2 * W + W, 16);
       snprintf(buff, sizeof(buff), "%d", temp);
       ssd1306_WriteString(buff, Font_11x18, White);

       //湿度
       for (size_t i = 0; i < sizeof(humi_fonts)/sizeof(humi_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 32, W, H, humi_fonts[i], sizeof(humi_fonts[0]), W);
       }
       //:
       ssd1306_DrawRegion(2 * W, 32, W, H, sig_fonts, sizeof(sig_fonts), W);
       //取湿度
       ssd1306_SetCursor(2 * W + W, 32);
       snprintf(buff, sizeof(buff), "%d", humi);
       ssd1306_WriteString(buff, Font_11x18, White);

       //光照
       for (size_t i = 0; i < sizeof(light_fonts)/sizeof(light_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 48, W, H, light_fonts[i], sizeof(light_fonts[0]), W);
       }
       //:
       ssd1306_DrawRegion(2 * W, 48, W, H, sig_fonts, sizeof(sig_fonts), W);
       //取光照
       ssd1306_SetCursor(2 * W + W, 46);
       light = 25;
       snprintf(buff, sizeof(buff), "%d", light);
       ssd1306_WriteString(buff, Font_11x18, White);

       ssd1306_UpdateScreen();
}

//主界面2
void ssd1306_set_main_2(uint32_t fan, uint32_t ptc, uint32_t hdr)
{
      // char buff[8];
       //绘制标题:  "宠物智能家居管理系统"
       ssd1306_Fill(Black);
       for (size_t i = 0; i < sizeof(head_fonts)/sizeof(head_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 0, W, H, head_fonts[i], sizeof(head_fonts[0]), W);
       }
       
       //风扇
       for (size_t i = 0; i < sizeof(fan_fonts)/sizeof(fan_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 16, W, H, fan_fonts[i], sizeof(fan_fonts[0]), W);
       }
       //:
       ssd1306_DrawRegion(2 * W, 16, W, H, sig_fonts, sizeof(sig_fonts), W);
       //判断开关
       if(fan == 1)
       {
           ssd1306_SetCursor(3 * W + W, 16);
           ssd1306_DrawRegion(3 * W + W, 16, W, H, button_fonts[0], sizeof(button_fonts[0]), W);
       }
       else
       {
           ssd1306_SetCursor(3 * W + W, 16);
           ssd1306_DrawRegion(3 * W + W, 16, W, H, button_fonts[1], sizeof(button_fonts[1]), W);
       }

       //加热片
       for (size_t i = 0; i < sizeof(ptc_fonts)/sizeof(ptc_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 32, W, H, ptc_fonts[i], sizeof(ptc_fonts[0]), W);
       }
       //:
       ssd1306_DrawRegion(2 * W, 32, W, H, sig_fonts, sizeof(sig_fonts), W);
       if(ptc == 1)
       {
           ssd1306_SetCursor(3 * W + W, 32);
           ssd1306_DrawRegion(3 * W + W, 32, W, H, button_fonts[0], sizeof(button_fonts[0]), W);
       }
       else
       {
           ssd1306_SetCursor(3 * W + W, 32);
           ssd1306_DrawRegion(3 * W + W, 32, W, H, button_fonts[1], sizeof(button_fonts[1]), W);
       }

       //加湿器
       for (size_t i = 0; i < sizeof(hdr_fonts)/sizeof(hdr_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W , 48, W, H, hdr_fonts[i], sizeof(hdr_fonts[0]), W);
       }
       //:
       ssd1306_DrawRegion(3 * W, 48, W, H, sig_fonts, sizeof(sig_fonts), W);
       if(ptc == 1)
       {
           ssd1306_SetCursor(3 * W + W, 48);
           ssd1306_DrawRegion(3 * W + W, 48, W, H, button_fonts[0], sizeof(button_fonts[0]), W);
       }
       else
       {
           ssd1306_SetCursor(3 * W + W, 48);
           ssd1306_DrawRegion(3 * W + W, 48, W, H, button_fonts[1], sizeof(button_fonts[1]), W);
       }

       ssd1306_UpdateScreen();
}

//展示服务器设置界面
void show_net_set(uint32_t fan, uint32_t ptc, uint32_t hdr, uint32_t val)
{
    //云平台控制
    ssd1306_Fill(Black);
    for (size_t i = 0; i < sizeof(cloud_fonts)/sizeof(cloud_fonts[0]); i++) {
        ssd1306_DrawRegion(i * W , 0, W, H, cloud_fonts[i], sizeof(cloud_fonts[0]), W);
    }

    //绘制具体的逻辑

    //如果是风扇
    if(fan)
    {
        //风扇
        for (size_t i = 0; i < sizeof(fan_fonts)/sizeof(fan_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W + W, 32, W, H, fan_fonts[i], sizeof(fan_fonts[0]), W);
       }

        //:
       ssd1306_DrawRegion(2 * W + W, 32, W, H, sig_fonts, sizeof(sig_fonts), W);
       if(val == 1)
       {
           ssd1306_SetCursor(2 * W + W + W, 32);
           ssd1306_DrawRegion(2 * W + W + W, 32, W, H, button_fonts[0], sizeof(button_fonts[0]), W);
       }
       else
       {
           ssd1306_SetCursor(2 * W + W + W, 32);
           ssd1306_DrawRegion(2 * W + W + W, 32, W, H, button_fonts[1], sizeof(button_fonts[1]), W);
       }
    }

    //如果是加热片
    if(ptc)
    {
        for (size_t i = 0; i < sizeof(ptc_fonts)/sizeof(ptc_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W + W, 32, W, H, ptc_fonts[i], sizeof(ptc_fonts[0]), W);
       }

        //:
       ssd1306_DrawRegion(3 * W + W + W, 32, W, H, sig_fonts, sizeof(sig_fonts), W);
       if(val == 1)
       {
           ssd1306_SetCursor(3 * W + W + W, 32);
           ssd1306_DrawRegion(3 * W + W + W, 32, W, H, button_fonts[0], sizeof(button_fonts[0]), W);
       }
       else
       {
           ssd1306_SetCursor(3 * W + W + W, 32);
           ssd1306_DrawRegion(3 * W + W + W, 32, W, H, button_fonts[1], sizeof(button_fonts[1]), W);
       }
    }

    //如果是加湿器
    if(hdr)
    {
        for (size_t i = 0; i < sizeof(hdr_fonts)/sizeof(hdr_fonts[0]); i++) {
            ssd1306_DrawRegion(i * W + W, 32, W, H, hdr_fonts[i], sizeof(hdr_fonts[0]), W);
       }

        //:
       ssd1306_DrawRegion(3 * W + W, 32, W, H, sig_fonts, sizeof(sig_fonts), W);
       if(val == 1)
       {
           ssd1306_SetCursor(3 * W + W + W, 32);
           ssd1306_DrawRegion(3 * W + W + W, 32, W, H, button_fonts[0], sizeof(button_fonts[0]), W);
       }
       else
       {
           ssd1306_SetCursor(3 * W + W + W, 32);
           ssd1306_DrawRegion(3 * W + W + W, 32, W, H, button_fonts[1], sizeof(button_fonts[1]), W);
       }
    }

    ssd1306_UpdateScreen();
}

#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(ssd1306_bitmap, bitmap test);
#endif
